package com.ty.day8;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * Created by IntelliJ IDEA.
 *
 * @author : txy
 * @create : 2023/12/1 9:56
 */
//客户端
public class SocketClient {
    private Socket socket;
    public SocketClient(){
        try {
            System.out.println("连接服务器");
            socket=new Socket("localhost",8886);
            System.out.println("连接成功");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    public void start() throws IOException{
        //io操作，输出流，写数据给服务器
        OutputStream os = socket.getOutputStream();
//        OutputStreamWriter osw = new OutputStreamWriter(os);
//        BufferedWriter bw = new BufferedWriter(osw);
        Scanner sc = new Scanner(System.in);
        String s;
        while (!(s=sc.nextLine()).isEmpty()){
            os.write(s.getBytes());
//            bw.write(s);
//            bw.flush();
        }
        os.close();
    }

    public static void main(String[] args) throws IOException {
        SocketClient client = new SocketClient();
        client.start();
    }
}
